package org.example;

import reactor.core.publisher.Mono;
import reactor.netty.DisposableServer;
import reactor.netty.http.server.HttpServer;

/**
 * @author chenye
 */
public class WebServerExample {
    public static final int PORT = 8080;

    public static void main(String[] args) {
        DisposableServer server = HttpServer.create()
                .port(PORT)
                .handle((httpInfos, response) -> {
                    System.out.println("request path : " + httpInfos.path());
                    if (httpInfos.path().equals("hello")) {
                        return response.sendString(Mono.just("Hello, World!"));
                    } else {
                        return response.sendNotFound();
                    }
                }).bindNow();
        System.out.println("start server port :" + PORT);
        server.onDispose().block();
    }
}
